;/*=============================================================================
;#    The element-comm is a tentative program used to test our ideas.           
;#                       Copyright (C)  bgao                                    
;#
;#     This program is free software; you can redistribute it and/or            
;#      modify it under the terms of the GNU General Public License             
;#     as published by the Free Software Foundation; either version 2           
;#         of the License, or (at your option) any later version.               
;#
;#     This program is distributed in the hope that it will be useful,          
;#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
;#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
;#             GNU General Public License for more details.                    
;#
;#    You should have received a copy of the GNU General Public License        
;#     along with this program; if not, write to the Free Software             
;#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
;#                       MA  02110-1301, USA.                                  
;#==============================================================================
;# $Id$ 
;#
;# $Author$ 
;#
;# $Revision$ 
;#
;# $Date$ 
;#
;# Description: 
;#
;=============================================================================*/
	GET option.inc
	GET 2410addr.inc

 if :def: __ARMCC_REALVIEW2_2
	PRESERVE8
	REQUIRE8	{TRUE}
 endif
 
	area BOOT, code, readonly
	entry
boot_start
    ; Exception vector table (physical address = 0x00000000)
    b	Reset
    b	HandlerUndef
    b	HandlerSWI
    b	HandlerPrefetchAbort
    b	HandlerDataAbort
    b	HandlerNotUsed
    b	HandlerIRQ
    b	HandlerFIQ
 
;======================================================
; ENTRY  
;======================================================

Reset
    ; Perform a soft reset of the system.  Put the CPU into the
    ; same state as it would be if it had been reset
;    mov	r0, #0
;    mcr	p15, 0, r0, c7, c7, 0		;@ invalidate I,D caches
;    mcr	p15, 0, r0, c7, c10, 4		;@ drain WB
;    mcr	p15, 0, r0, c8, c7, 0		;@ invalidate I & D TLBs
;    mrc	p15, 0, r0, c1, c0, 0		;@ ctrl register
;    bic	r0, r0, #0x000f			;@ ............wcam
;    bic	r0, r0, #0x1100			;@ ...i...s........
;    mcr	p15, 0, r0, c1, c0, 0		;@ ctrl register
    add	sp, pc, #0x7F0			; Set stack
    
   
	;watch dog disable
    ldr	r0,=WTCON        
	ldr	r1,=0x0         
	str	r1,[r0]

	;all interrupt disable
	ldr	r0,=INTMSK
	ldr	r1,=0xffffffff  
	str	r1,[r0]

	;all sub interrupt disable
	ldr	r0,=INTSUBMSK
	ldr	r1,=0x7ff		
	str	r1,[r0]

    ;To reduce PLL lock time, adjust the LOCKTIME register. 
    ldr r0, =LOCKTIME
    ldr r1, =0xffffff
    str r1, [r0]
	
    ;Config slow clock mode
    ldr r0, =CLKSLOW
    ldr r1, =4;
    str r1, [r0];
              
    ;Configure MPLL = 200M
    ldr r0, =MPLLCON          
    ldr r1, =((M_MDIV<<12)+(M_PDIV<<4)+M_SDIV)
    str r1, [r0]
    
    ;Config div for PCLK
    ldr r0, =CLKDIVN
    ldr r1, =((M_HDIVN<<1)+(M_PDIVN))
    str r1, [r0]

	;jump to boot_wsn.s
	ldr pc,=0x30008000

;should add code for sram contoller init


;
; Exception handling functions
;
HandlerUndef
1	b	%b1		; infinite loop

HandlerSWI
1	b	%b1		; infinite loop

HandlerPrefetchAbort
1	b	%b1		; infinite loop

HandlerDataAbort
1	b	%b1		; infinite loop

HandlerIRQ
1	b	%b1		; infinite loop

HandlerFIQ
1	b	%b1		; infinite loop

HandlerNotUsed
1	b	%b1		; infinite loop


	
	LTORG
	
    ALIGN
    AREA RamData, DATA, READWRITE

        ^   _ISR_STARTADDRESS
HandleReset 	#   4
HandleUndef 	#   4
HandleSWI   	#   4
HandlePrefetchAbort    #   4
HandleDataAbort    #   4
HandleNotUsed  #   4
HandleIRQ   	#   4
HandleFIQ   	#   4

	end
